﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Printing;

namespace S3.Common
{
    class PrintBill : PrintDocument
    {
        #region Static Local Variables

        static int CurChar;
        #endregion

        #region  Property Variables

        private Font _font;

        #endregion

        #region  Class Properties

        public string TextToPrint { get; set; }

        public Font PrinterFont
        {
            // Allows the user to override the default font
            get { return _font; }
            set { _font = value; }
        }

        #endregion

        #region  Class Constructors

        public PrintBill()
            : base()
        {
            TextToPrint = string.Empty;
        }


        public PrintBill(string strContent)
            : base()
        {
            TextToPrint = strContent;
            DefaultPageSettings.PaperSize = new PaperSize("A4", Convert.ToInt32(Properties.Resources.PageWidth), Convert.ToInt32(Properties.Resources.PageHeight));
        }
        #endregion

        #region  onbeginPrint

        protected override void OnBeginPrint(PrintEventArgs e)
        {
            base.OnBeginPrint(e);
            if (_font == null)
            {
                _font = new Font("Tahoma", 10);
            }
        }

        #endregion

        #region  OnPrintPage

        protected override void OnPrintPage(PrintPageEventArgs e)
        {
            base.OnPrintPage(e);

            int x = e.MarginBounds.Left;
            int y = e.MarginBounds.Top;
            Brush brush = new SolidBrush(Color.Black);
            e.Graphics.DrawString(TextToPrint,
                _font, brush, x, y);
            y += 15;
            if (y >= e.MarginBounds.Bottom)
            {
                e.HasMorePages = true;
                return;
            }

            e.HasMorePages = false;
        }

        #endregion

        #region  RemoveZeros
        /// <summary>
        /// Function to replace any zeros in the size to a 1
        /// Zero's will mess up the printing area
        /// </summary>
        /// <param name=value>Value to check</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public int RemoveZeros(int value)
        {
            //Check the value passed into the function,
            //if the value is a 0 (zero) then return a 1,
            //otherwise return the value passed in
            switch (value)
            {
                case 0:
                    return 1;
                default:
                    return value;
            }
        }
        #endregion

    }
}
